package com.atguigu.flink.util;

import com.atguigu.flink.pojo.WaterSensor;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Smexy on 2022/11/22
 */
public class MyUtil
{

    private static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //打印TimeWindow window
    public static String parseTimeWindow(TimeWindow window){

        Date startDate = new Date(window.getStart());
        Date endDate = new Date(window.getEnd());

        return "[" + simpleDateFormat.format(startDate) +"," + simpleDateFormat.format(endDate) +")";
    }

    //将Iterable<T> elements 转为List
    public static <T> List<T> parseList(Iterable<T> elements){

        List<T> result = new ArrayList<>();

        for (T e : elements) {
            result.add(e);
        }

        return result;

    }
}
